﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySkiPatrolEntity;

namespace MySkiPatrolVAL
{
    public class EventVLO
    {
        private Event EVENT;

        private void AddValidationError(Error err)
        {
            if (EVENT.DataTransaction.TransactionErrors == null)
            {
                EVENT.DataTransaction.TransactionErrors = new List<Error>();
            }

            EVENT.DataTransaction.TransactionErrors.Add(err);
        }

        public Event Validate(Event data)
        {
            EVENT = data;

            //Must have an ID
            if (string.IsNullOrEmpty(EVENT.ID))
            {
                //NEW EVENT?
                if (EVENT.DataTransaction.Action == DataAction.Add)
                {
                    EVENT.ID = Guid.NewGuid().ToString();
                }
                else
                {
                    AddValidationError(new Error("VAL11000", "Your event is missing an ID"));
                }
            }

            //OWNER ID (PersonID)
            if (string.IsNullOrEmpty(EVENT.OwnerID))
            {
                AddValidationError(new Error("VAL11001", "Your event is missing an owner ID"));
            }

            //STARTDATE
            if (string.IsNullOrEmpty(EVENT.StartDate.ToUniversalTime().ToString()))
            {
                AddValidationError(new Error("VAL11002", "Your event is missing a start date/time"));
            }

            //TITLE must be present
            if (string.IsNullOrEmpty(EVENT.Title))
            {
                AddValidationError(new Error("VAL11003", "Your event is missing a title"));
            }

            //ALL Day Event logic...
            //if (EVENT.AllDayEvent)
            //{
            //    //make the ENDDATE the same, set STARTTIME/ENDTIME
            //    EVENT.StartDate = DateTime.Parse(EVENT.StartDate.ToShortDateString() + " 00:00am");
            //    EVENT.EndDate = DateTime.Parse(EVENT.StartDate.ToShortDateString() + " 11:59pm");
            //}

            return EVENT;
        }
    }
}
